﻿using System;
using System.Data;
using System.Text;
using System.Data.OracleClient;
using DBUtility;//请先添加引用
namespace DBEmr.DAL
{
	/// <summary>
	/// 数据访问类NATIONALITY。
	/// </summary>
	public class NATIONALITY
	{
		public NATIONALITY()
		{
			DbHelperOra.connectionString=PubConstant.GetConfig("DBEMR");
		}
		#region  成员方法


		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string N_ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from NATIONALITY");
			strSql.Append(" where N_ID='"+N_ID+"' ");
			return DbHelperOra.Exists(strSql.ToString());
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public void Add(DBEmr.Model.NATIONALITY model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into NATIONALITY(");
			strSql.Append("N_ID,N_NAME,N_PYM");
			strSql.Append(")");
			strSql.Append(" values (");
			strSql.Append("'"+model.N_ID+"',");
			strSql.Append("'"+model.N_NAME+"',");
			strSql.Append("'"+model.N_PYM+"'");
			strSql.Append(")");
			DbHelperOra.ExecuteSql(strSql.ToString());
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public void Update(DBEmr.Model.NATIONALITY model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update NATIONALITY set ");
			strSql.Append("N_NAME='"+model.N_NAME+"',");
			strSql.Append("N_PYM='"+model.N_PYM+"'");
			strSql.Append(" where N_ID='"+ model.N_ID+"' ");
			DbHelperOra.ExecuteSql(strSql.ToString());
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public void Delete(string N_ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete NATIONALITY ");
			strSql.Append(" where N_ID='"+N_ID+"' " );
			DbHelperOra.ExecuteSql(strSql.ToString());
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public DBEmr.Model.NATIONALITY GetModel(string N_ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select N_ID,N_NAME,N_PYM ");
			strSql.Append(" from NATIONALITY ");
			strSql.Append(" where N_ID='"+N_ID+"' " );
			DBEmr.Model.NATIONALITY model=new DBEmr.Model.NATIONALITY();
			DataSet ds=DbHelperOra.Query(strSql.ToString());
			if(ds.Tables[0].Rows.Count>0)
			{
				model.N_ID=ds.Tables[0].Rows[0]["N_ID"].ToString();
				model.N_NAME=ds.Tables[0].Rows[0]["N_NAME"].ToString();
				model.N_PYM=ds.Tables[0].Rows[0]["N_PYM"].ToString();
				return model;
			}
			else
			{
				return null;
			}
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select N_ID,N_NAME,N_PYM ");
			strSql.Append(" FROM NATIONALITY ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperOra.Query(strSql.ToString());
		}

		/*
		*/

		#endregion  成员方法
	}
}

